<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ArticleDao
 *
 * @author Binh
 */
class ArticleDao {
    public static function getArticles($idSubject) {
        $ds = array();
        $sql = sprintf("select * from articles where idSubject=%d", $idSubject);
        $helper = new MySqlDataAccessHelper;

        $helper->open();
        $rs = $helper->executeQuery($sql);
        if (FALSE === $rs) {
            echo mysql_error();
            return $ds;
        } else {
            while ($row = mysql_fetch_array($rs)) {
                $art = new ArticlePojo($row["id"],$row["name"],$row["idSubject"],$row["content"],$row["thumbnail"],$row["time"]);
                array_push($ds, $art);
            }
            $helper->close();
            return $ds;
        }
    }
    public static function getArticle($id) {
        $ds = array();
        $sql = sprintf("select * from articles where id=%d", $id);
        $helper = new MySqlDataAccessHelper;

        $helper->open();
        $rs = $helper->executeQuery($sql);
        if (FALSE === $rs) {
            echo mysql_error();
            return $ds;
        } else {
            if ($row = mysql_fetch_array($rs)) {
                $art = new ArticlePojo($row["id"],$row["name"],$row["idSubject"],$row["content"],$row["thumbnail"],$row["time"]);
                array_push($ds, $art);
            }
            $helper->close();
            return $ds;
        }
    }
    
    public static function getServices() {
        $ds = array();
        $sql = "select * from articles where idSubject/1000 >= 4 and idSubject/1000 < 5";
        $helper = new MySqlDataAccessHelper;

        $helper->open();
        $rs = $helper->executeQuery($sql);
        if (FALSE === $rs) {
            echo mysql_error();
            return $ds;
        } else {
            while ($row = mysql_fetch_array($rs)) {
                $art = new ArticlePojo($row["id"],$row["name"],$row["idSubject"],$row["content"],$row["thumbnail"],$row["time"]);
                array_push($ds, $art);
            }
            $helper->close();
            return $ds;
        }
    }
}

?>
